package org.example.controller;

import jakarta.annotation.Resource;
import org.example.pojo.Book;
import org.example.service.IBookService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author TonySong
 * @date 2024/5/14 0014
 * @time 16:16
 */
@RestController
@RequestMapping("/book")
public class BookController {

    @Resource
    private IBookService bookService;

    @GetMapping("/list")
    public List<Book> findAll(){
        return this.bookService.getBooks();
    }

    @GetMapping("/{id}")
    public Book findById(@PathVariable("id") Long id){
        return this.bookService.getBookById(id);
    }

    @GetMapping("/update/{bid}")
    public boolean updateAmount(@PathVariable("bid") Long bid){
        this.bookService.updateAmount(bid);
        return true;
    }

    @GetMapping("/show")
    public String show(){
        return this.bookService.show();
    }

}

